import { TaskDao } from "../dao/task";
const TaskDto = new TaskDao();
import { emailTo } from "../lib/email";
const schedule = require("node-schedule");
export async function test() {
  const tasks = await TaskDto.getTasks();
  console.log("tasks", tasks[0]);
  if (!tasks || tasks.length < 1) {
    throw new NotFound({
      message: "没有找到相关书籍",
    });
  } else {
    for (let i = 0; i < tasks.length; i++) {
      let job = schedule.scheduleJob("42 * * * * *", async function() {
        await emailTo(
          tasks[i].dataValues.to,
          tasks[i].dataValues.name,
          "",
          tasks[i].dataValues.info,
          function(b) {
            console.log(b, "info");
          }
        );
        console.log("The answer to life, the universe, and everything!1111");
      });
      let obj = {
        id: tasks[i].dataValues.id,
        job,
      };
      global.taskList.push(obj);
      // console.log("bbbbb");
    }
  }
}
